<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: create by allen.qiang
// +----------------------------------------------------------------------

/**
 * 会员反馈ajax类
 * @package  ajax
 * @subpackage  backend
 * @author   create by allen.qiang
 */

quanli_require('module/base/customer/custComment.class.php');

class ajax_bdchildrens{

    public function execute(){

        if( isset($_REQUEST['operFlg']) && quanli_is_int($_REQUEST['operFlg'])){

            switch( $_REQUEST['operFlg'] ){

                case 1:
                    $this->insertText();//保存反馈信息
                    break;
                case 2:
                    $this->isZhufu();//保存反馈信息
                    break;
                default:
                    returnJsonData('参数错误');
                    break;

            }

        } else{

            returnJsonData('参数错误');

        }

    }

  
    /**
     * 插入祝福语
     */
    public function insertText(){

        global $G_SHOP;

//        $activity = new entity('activities_extend');
//        $activity->activityNumber = $_REQUEST['act'];
//        $activity->creator = $_REQUEST['custID'];
//        if (!$G_SHOP->DBCA->fetch($activity)){
//            $activity->activityNumber = $_REQUEST['act'];
//            $activity->creator = $_REQUEST['custID'];
//            $activity->extend_1 = htmlspecialchars($_REQUEST['text']);
//            $activity->createTime = date('Y-m-d H:i:s');
//            $G_SHOP->DBCA->save($activity);
//
//            returnJsonData('活动祝福信息没有找到', 200);
//        }else{
//            returnJsonData('你已经填写过祝福信息', 400);
//        }


        if($G_SHOP->get_cookie_info('EBSIG_CITY_ID') != 110){
            returnJsonData('本活动仅限上海地区', 400);
        }


        //今天
        $today = date('Y-m-d');
        $starttime = $today." 00:00:00";
        $endtime = $today." 23:59:59";

        $sql = "SELECT extend_1 FROM activities_extend WHERE
        creator=".$_REQUEST['custID']." AND createTime BETWEEN '".$starttime."' AND '".$endtime."' ORDER BY createTime DESC   LIMIT 1 ";
        $result = $G_SHOP->DBCA->stmt_query($sql);
        if(!$result){
            $sql_insert = "INSERT INTO activities_extend (UUID,creator,createTime,activityNumber,extend_1)
            VALUES
             ('".date('Y-m-d H:i:s').time()."','".$_REQUEST['custID']."','".date('Y-m-d H:i:s')."','500','".htmlspecialchars($_REQUEST['text'])."')";
            if($G_SHOP->DBCA->stmt_query($sql_insert)){
                returnJsonData('活动祝福信息插入成功', 200);
            }else{
                returnJsonData('活动祝福信息插入失败', 400);
            }
        }else{
            $sql_update = "UPDATE activities_extend SET extend_1='".htmlspecialchars($_REQUEST['text'])."' WHERE creator='".$_REQUEST['custID']."' and
            createTime BETWEEN '".$starttime."' and '".$endtime."'";
            //echo $sql_update;die;
            if($G_SHOP->DBCA->stmt_query($sql_update)){
                returnJsonData('活动祝福信息更新成功', 200);
            }else{
                returnJsonData('活动祝福信息更新失败', 400);
            }
        }

    }


    public  function  isZhufu(){
        global $G_SHOP;

        $activity = new entity('activities_extend');
        $activity->activityNumber = $_REQUEST['act'];
        $activity->creator = $_REQUEST['custID'];
        if (!$G_SHOP->DBCA->fetch($activity)){
            returnJsonData('活动祝福信息没有找到', 200);
        }else{
            returnJsonData('你已经填写过祝福信息', 400);
        }
    }

}


